using UnityEngine;
using LitJson;
using System.IO;

namespace Framework.Save
{
    public static class SaveManager
    {
        public static void Save(string name, JsonData data, params string[] relPath)
        {
            var dir = Path.Combine(Application.dataPath, Path.Combine(relPath));
            if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
            var path = Path.Combine(dir, $"{name}.json");
            string json = data.ToString();
            File.WriteAllText(path, json);
        }

        public static JsonData Load(string name, params string[] relPath)
        {
            var dir = Path.Combine(Application.dataPath, Path.Combine(relPath));
            var path = Path.Combine(dir, $"{name}.json");
            var json = File.ReadAllText(path);
            return JsonMapper.ToObject(json);
        }
    }
}